<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const deepClone = (data)=>{
            if(data === null || data === undefined){
                return data
            }
            const type = data.prototype ? data.prototype.toString() : data.toString()

            if(type === '[object File]'){// 拷贝文件
                const _file = new File([data],data.name,{type: data.type})
                _file.uid = data.uid
                return _file
            }else if(data instanceof Array){// 拷贝数组
                const _arr = []
                for(let i = 0;  i < data.length; i++){
                    _arr.push(deepClone(data[i]))
                }
                return _arr
            }else if (data instanceof Object){
                const _obj = {},
                keys = Object.keys(data)
                for(let i = 0; i < keys.length; i++){
                    _obj[keys[i]] = deepClone(data[keys[i]])
                }
                return _obj
            }else if(type === '[object Date]'){ // // 处理 Date 对象
                return new Date(date.getTime())
            }else if(type === '[object RegExpl]'){
                return new RegExp(data)
            }else if(type === '[object  Function]'){
                return data.bind({})
            }else {
                return data
            }
        }

        
        let originObj = {
            a:1,
            b:"hello",
            c:[1,2,3],
            d:{e: "world"},
            f: function(){
                console.log('hello world');
            }
        }

        let cloneObj = deepClone(originObj)

        cloneObj.a = 2
        cloneObj.b = 'wolrd'
        cloneObj.c[0] = 4
        cloneObj.d.e = '123456'

        console.log('originObj',originObj);
        console.log('cloneObj',cloneObj);
        
    </script>
</body>
</html>